package mysql

import (
	"fmt"
	"time"
)
type UserSheet struct {
	Id int
	User_id int
	Createtime time.Time `xorm:"createtime created" json:"createtime" description:"创建时间"`
	Song_id int `json:"song_id"`
	Song_name string `json:"song_name"`
	Singer string `json:"singer"`
	Singer_id int `json:"singer_id"`
}
func (sink MysqlSink) GetUsheet(song_id int,user_id int)(has bool,err error)  {
	model := new(UserSheet)
	has, err = sink.database.Where("song_id=? and user_id =?", song_id,user_id).Get(model)
	if err !=nil{
		fmt.Println(err)
		return
	}
	return has,nil
}
func (sink MysqlSink)GetSheets(user_id int)(rows []UserSheet,err error) {
	model := make([]UserSheet, 0)
	err = sink.database.Where(" user_id = ?", user_id).Find(&model)
	if err !=nil{
		fmt.Println(err)
		return
	}
	return model,nil
}
//插入数据
func (sink MysqlSink) InsUsheet(data UserSheet)(res int64,err error)  {
	affected, err :=sink.database.Insert(data)
	if err !=nil{
		fmt.Println(err)
		return
	}
	return affected,nil
}
